<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/7/10 0010
 * Time: 17:12
 */
namespace App\Content\Models;

use App\Base\Models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;

class InfoCollectionModel extends  BaseModel {

    //use SoftDeletes;
    /**
     * 表名--文章评论表
     * @var string
     */
    public $table="info_collection";
    /**
     * 时间自动
     * @var bool
     */
    public $timestamps=true;
    /**
     * The name of the "created at" column.
     *
     * @var string
     */
    const CREATED_AT = 'create_time';  //修改添加时间字段
    /**
     * The name of the "updated at" column.
     *
     * @var string
     */
    const UPDATED_AT = 'update_time';

    /**
     * 删除
     */
    //const DELETED_AT = 'delete_time';
    /**
     * 模型的日期字段保存格式。
     */
    protected $dateFormat = 'U';

    /**
     * 关联用户
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public  function user(){
        return $this->hasOne(WxUsersModel::class,"uid","user_id");
    }

    /**
     * 关联文章
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function article(){
        return $this->hasOne(ArticleModel::class,"item_id","itemid");
    }

    /**
     * 用户模型
     * @return WxUsersModel
     */
    public function getWxUsersModel(){
        return app()->make(WxUsersModel::class);
    }

    public function setUserIdAttribute($value){
        $this->attributes['user_id'] = $value;
        $info=$this->getWxUsersModel()->newQuery()->where("uid",$value)->first();
        $this->attributes['user_name'] = $info['nickname']??'';
        $this->attributes['user_profile_image_url'] =  $info['headimgurl']??'';
    }

}